<template>
  <!-- 维修记录 -->
  <div class="Wxjl">
    <!-- 第一行 -->
    <el-row>
      <el-col class="header_col">
        <div class="header_title">维修记录</div>
      </el-col>
    </el-row>
    <!-- 第二行 -->
    <el-row>
      <el-col class="search_col" :span="16">
        <el-form
          ref="form"
          :model="search_Data"
          label-width="80px"
          size="medium"
          :label-position="labelPosition"
        >
          <div class="search_col_top">
            <el-form-item label="开始时间">
              <el-date-picker
                type="date"
                placeholder="选择开始日期"
                v-model="search_Data.startTime"
                style="width: 300px"
                value-format="yyyy-MM-dd"
                clearable
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="结束时间">
              <el-date-picker
                type="date"
                placeholder="选择结束日期"
                v-model="search_Data.overTime"
                style="width: 300px"
                clearable
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </div>
          <!-- 二排 -->
          <div class="search_col_bottom">
            <el-form-item label="维修状态" size="small">
              <el-select
                v-model="search_Data.testStatusInfo"
                placeholder="请选择器材类型"
                clearable
                style="width: 300px"
              >
                <el-option label="维修中" value="1"></el-option>
                <el-option label="待维修" value="2"></el-option>
                <el-option label="维修完成" value="3"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="搜索">
              <el-input
                v-model="search_Data.equipmentNameInfo"
                placeholder="请输入维修单号"
                clearable
                style="width: 300px"
              ></el-input>
            </el-form-item>
          </div>
        </el-form>
      </el-col>
      <!-- 按钮 -->
      <el-col class="search_col" :span="8">
        <div class="search_col_right">
          <!-- 重置 -->
          <el-button
            type="success"
            icon="el-icon-plus"
            @click="onReset"
            size="mediu"
            >重置</el-button>
          <el-button
            type="primary"
            icon="el-icon-zoom-in"
            @click="onSearch"
            size="mediu"
            >查询</el-button
          >
        </div>
      </el-col>
    </el-row>
    <!-- 表格 -->
    <el-table :data="WxjlData" style="width: 100%">
      <el-table-column prop="id" label="维修单号" align="center">
      </el-table-column>
      <el-table-column
        prop="equipment.id"
        label="装备名称"
        align="center"
      >
        <template slot-scope="scope">
          <span>{{
            scope.row.equipment.id == 1
              ? "重型坦克"
              : scope.row.equipment.id == 2
              ? "轻型坦克"
              : scope.row.equipment.id == 3
              ? "装甲步兵战车"
              : scope.row.equipment.id == 4
              ? "水陆两栖战车"
              : "Null"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="equipmentNumber" label="装备编号" align="center">
      </el-table-column>
      <el-table-column prop="desc" label="故障描述" align="center">
      </el-table-column>
      <el-table-column label="开始时间" align="center">
        <template slot-scope="scope">{{
          scope.row.startTime | formatTimer
        }}</template>
      </el-table-column>
      <el-table-column label="结束时间" align="center">
        <template slot-scope="scope">{{
          scope.row.endTime | formatTimer
        }}</template>
      </el-table-column>
      <el-table-column prop="testStatus" label="维修状态" align="center">
        <template slot-scope="scope">
          <span>{{
            scope.row.testStatus == 1
              ? "维修中"
              : scope.row.testStatus == 2
              ? "待维修"
              : scope.row.testStatus == 3
              ? "维修完成"
              : ""
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            class="view_btn"
            type="primary"
            icon="el-icon-view"
            @click="viewInfo(scope.row)"
            size="small"
          >
          </el-button>
          <el-button
            class="del_btn"
            type="primary"
            icon="el-icon-delete"
            @click="delInfo(scope.row.id)"
            size="small"
          >
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 页码 -->
    <el-col :span="24">
      <div class="grid_content">
        <span class="page_total"
          >共{{ Math.ceil(total / wxjl_limit) }}页/{{ total }}条数据</span
        >
        <el-pagination
          @current-change="wxjl_changePage"
          :page-size="wxjl_limit"
          layout="prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
        <span class="go_page">跳转</span>
      </div>
    </el-col>
  </div>
</template>

<script>
export default {
  data: function () {
    return {
      labelPosition: "left",
      search_Data: {
        startTime: "",
        overTime: "",
        testStatusInfo: "",
        equipmentNameInfo: "",
      },
      WxjlData: [],
      wxjl_page: 1,
      wxjl_limit: 5,
      total: 0,
    };
  },
  methods: {
    // 获取数据
    getWxjlData: function () {
      this.$axios({
        url: "/keepRecord/queryAllRecord",
        method: "post",
        params: {
          page: this.wxjl_page,
          limit: this.wxjl_limit,
        },
        data: {
          startTime: this.search_Data.startTime,
          endTime: this.search_Data.overTime,
          testStatus: this.search_Data.testStatusInfo,
          id: this.search_Data.equipmentNameInfo,
        },
      }).then((res) => {
        // console.log("维修记录", res.data);
        if (res.data.code == 0) {
          this.WxjlData = res.data.data;
          this.total = res.data.total;
          // this.$message.success("数据加载成功！");
        } else {
          this.$message.error("数据加载失败！");
        }
      });
    },
    // 重置
    onReset: function () {
      this.search_Data.startTime = "";
      this.search_Data.overTime = "";
      this.search_Data.testStatusInfo = "";
      this.search_Data.equipmentNameInfo = "";
      this.wxjl_page = 1;
      this.getWxjlData();
    },
    // 维修记录添加
    onAddInfo: function () {
      this.$router.push("/home/Wxjl_add");
    },
    // 搜索
    onSearch: function () {
      this.getWxjlData();
    },

    // 查看
    viewInfo: function (row) {
      let wxjl_data = row;
      this.$store.state.tjy_vuex.wxjl_data = wxjl_data;
      sessionStorage.setItem("wxjlInfo", JSON.stringify(wxjl_data));
      this.$router.push("/home/Wxjl_view");
      // console.log(row);
    },
    // 删除
    delInfo: function (delId) {
      let del_id = delId;
      // console.log(del_id);
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios({
            url: "/keepRecord/delete",
            method: "delete",
            params: {
              id: del_id,
            },
          }).then((res) => {
            if (res.data.code == 0) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.getWxjlData();
            } else {
              this.$message({
                type: "info",
                message: "删除失败！！！",
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消删除",
          });
        });
    },
    // 页码改变
    wxjl_changePage: function (page) {
      this.wxjl_page = page;
      this.getWxjlData();
    },
  },
  // 日期时间格式化过滤器
  filters: {
    formatTimer: function (time) {
      let date = new Date(time);
      let y = date.getFullYear();
      let MM = date.getMonth() + 1;
      MM = MM < 10 ? "0" + MM : MM;
      let d = date.getDate();
      d = d < 10 ? "0" + d : d;
      let h = date.getHours();
      h = h < 10 ? "0" + h : h;
      let m = date.getMinutes();
      m = m < 10 ? "0" + m : m;
      let s = date.getSeconds();
      s = s < 10 ? "0" + s : s;
      // return y + "-" + MM + "-" + d + " " + h + ":" + m;
      return y + "-" + MM + "-" + d;
    },
  },
  mounted: function () {
    this.getWxjlData();
  },
};
</script>

<style lang="less" scoped>
.Wxjl {
  //   background: yellowgreen;
  width: 100%;
  height: 100%;
  min-width: 1440px;
  .header_col {
    margin-top: 20px;
    padding-left: 30px;
    min-width: 1440px;
  }

  .header_title {
    height: 40px;
    width: 100%;
    font-size: 24px;
    line-height: 40px;
    color: #344563;
    font-weight: bolder;
  }

  // 搜索
  .search_col {
    height: 100px;
    margin-top: 20px;
    display: flex;
    padding-left: 30px;
    
    .el-form-item {
      margin-right: 150px;
    }

    .search_col_top {
      width: 850px;
      height: 50%;
      display: flex;
      
    }
    .search_col_bottom {
      width: 850px;
      height: 50%;
      display: flex;

    }
 
    .reset_btn {
      background: #61a4e4;
      margin-right: 30px;
      border-color: #61a4e4;

    }
    .search_btn {
      // text-align: center;
      background: #64c8bc;
      border-color: #64c8bc;
    }
  }

  // 表格
  .el-table {
    border: none;
    margin-top: 20px;
    // border-top: 1px solid #aaa;
    // border-bottom: 1px solid #aaa;
  }
  .view_btn {
    font-size: 20px;
    color: #61a4e4;
    background: #eef6fc;
    border-color: #eef6fc;
  }
  .del_btn {
    font-size: 20px;
    font-weight: bolder;
    color: #ffc5c5;
    background: #fef3f3;
    border-color: #fef3f3;
  }

  // 底部页码
  .grid_content {
    // background: #61a4e4;
    line-height: 40px;
    position: relative;

    .el-pagination {
      border-radius: 10px;
      position: absolute;
      top: 25px;
      right: 90px;
      color: #a1a1a1;
    }
    .go_page {
      font-size: 14px;
      position: absolute;
      top: 20px;
      right: 50px;
      color: #7161c5;
      &:hover {
        cursor: pointer;
      }
    }
    .page_total {
      font-size: 14px;
      position: absolute;
      top: 20px;
      right: 620px;
      color: #a8afbc;
    }
  }
}
</style>